﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace The_LarX
{
    public static class ArrayTool
    {
        public static List<Vector3> MakeArray(Actor actor,
            int OneDCount, Vector3 PosIncremental,
            int TwoDCount, Vector3 Two2DIncremental,
            int ThreeDCount, Vector3 Three3DIncremental)
        {
            List<Vector3> Positions = new List<Vector3>();

            Vector3 startPosition = actor.Position;            

            for (int i = 1; i < OneDCount + 1; i++)
            {
                //// 1D
                Vector3 d1Position = startPosition +
                    (PosIncremental * i);
                if (!Positions.Contains(d1Position))
                {
                    Positions.Add(d1Position);
                }

                for (int k = 0; k < TwoDCount; k++)
                {
                    //// 2D
                    Vector3 d2Position = d1Position +
                    (Two2DIncremental * k);
                    if (!Positions.Contains(d2Position))
                    {
                        Positions.Add(d2Position);
                    }

                    for (int j = 1; j < ThreeDCount + 1; j++)
                    {
                        //// 3D
                        Vector3 d3Position = d2Position +
                            (Three3DIncremental * j);
                        if (!Positions.Contains(d3Position))
                        {
                            Positions.Add(d3Position);
                        }
                    }
                }
            }

            return Positions;
        }

        public static void ActorArray(Actor actor,
            int OneDCount, Vector3 PosIncremental,
            int TwoDCount, Vector3 Two2DIncremental, 
            int ThreeDCount, Vector3 Three3DIncremental)
        {
            if (actor.ComponentParent == null)
                throw new Exception("Actor must have it's Component Parent assigned");
            if (!(actor.ComponentParent is IHasActor))
                throw new Exception("Actor Parent can't handle Clonage. Use Interface IHasActor");

            List<Vector3> positions = MakeArray(actor, OneDCount, PosIncremental,
                TwoDCount, Two2DIncremental, ThreeDCount, Three3DIncremental);

            for (int i = 0; i < positions.Count; i++)
            {
                IHasActor comp = (IHasActor)actor.ComponentParent.Clone();
                comp.Actor.Position = positions[i];
            }
        }
    }
}
